<?php

namespace Project\ScrumBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class AffectationType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $id = $options['attr'];
        $builder
                ->add('refUserstorie', 'entity', array(
                    'class' => 'Project\ScrumBundle\Entity\Userstories',
                    'property' => 'role',
                    'label' => 'User story : ',
                    'query_builder' => function (\Doctrine\ORM\EntityRepository $er) {
                            return $er->createQueryBuilder('userstory')
                                    ->where('userstory.affectation = :param')
                                    ->setParameter('param', false);
                    },
                ))
                ->add('refUtilisateur', 'entity', array(
                    'class' => 'Project\ScrumBundle\Entity\Utilisateur',
                    'property' => 'email',
                    'label' => 'Personne : ',
                    'query_builder' => function (\Doctrine\ORM\EntityRepository $er) {
                            return $er->createQueryBuilder('utilisateur')
                                    ->where('utilisateur.refRole != :param')
                                    ->andWhere('utilisateur.refRole != :param2')
                                    ->andWhere('utilisateur.affectation = :param3')
                                    ->setParameters(array('param' => 4, 'param2' => 1, 'param3' => true)); // 4 = ROLE_CLIENT, 1 = ROLE_ADMIN
                    },
                    ))
               
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'data_class' => 'Project\ScrumBundle\Entity\Affectation'
        ));
    }

    public function getName() {
        return 'project_scrumbundle_affectationtype';
    }

}
